package com.zdj.data.net;

import java.net.CookieManager;
import java.net.CookiePolicy;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * Created by zdj on 16-5-30.
 */

public class OkHttpNetCenter {

    // 连接超时时间
    protected static final int CONNECT_TIMEOUT = 15 * 1000;
    // 最大连接数
    protected static final int MAX_CONNECTIONS = 15;
    // 失败重连次数
    protected static final int MAX_RETRIES = 3;
    // 失败重连间隔时间
    protected static final int RETRIES_TIMEOUT = 5 * 1000;
    // 响应超时时间
    protected static final int RESPONSE_TIMEOUT = 15 * 1000;
    // 默认编码
    public static final String CONTENT_ENCODING = "UTF-8";
    // 默认Content-Type
    public static final String DEFAULT_CONTENT_TYPE = "application/json";

    private volatile static OkHttpNetCenter instance;
    private OkHttpClient mOkHttpClient;


    public OkHttpNetCenter() {
        initOkHttpClient();
    }

    public static OkHttpNetCenter getInstance() {
        if (instance == null) {
            instance = new OkHttpNetCenter();
        }
        return instance;
    }

    private void initOkHttpClient() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(CONNECT_TIMEOUT, TimeUnit.MILLISECONDS);
        builder.writeTimeout(10, TimeUnit.SECONDS);
        builder.readTimeout(30, TimeUnit.SECONDS);
        mOkHttpClient = builder.build();
    }

    public OkHttpClient getmOkHttpClient() {
        return mOkHttpClient;
    }
}
